package rpg.core
{
	import rpg.role.Hero;
	import rpg.update.CameraUpdate;

	public class BlinkComponent extends AutoDestroyComponent
	{
		private var targetX : int;
		private var targetY : int;
		private var role : Hero;

		public function BlinkComponent(type : * = null)
		{
			super(type == null ? BlinkComponent : type);
		}

		override public function notifyAdded() : void
		{
			role = owner as Hero;
			role.isRush = true;
		}

		public function setTargetPosition(targetX : int , targetY : int) : void
		{
			this.targetX = targetX;
			this.targetY = targetY;
		}

		override public function timeOut() : void
		{
			super.destroy();
			if(CameraUpdate.aimHero == role)
			{
				CameraUpdate.sceneX += targetX - role.mapX;
				CameraUpdate.sceneY += targetY - role.mapY;
			}
			role.mapX = targetX;
			role.mapY = targetY;
			role.isRush = false;
		}
	}
}